package com.cw.jeeyt.dao.impl.facade;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.cw.jeeyt.dao.intf.facade.FacadeParamFieldDao;
import com.cw.jeeyt.dao.mapper.facade.FacadeParamFieldMapper;
import com.cw.jeeyt.dao.model.facade.FacadeParamFieldDo;
import com.cw.jeeyt.dao.model.facade.FacadeParamFieldExample;
import com.cw.jeeyt.dao.model.facade.FacadeParamFieldKeyDo;
import com.cw.jeeyt.dao.query.facade.FacadeParamFieldQuery;
import com.cw.lang.common.utils.StringUtil;
import com.cw.lang.common.dao.AbstractBaseDaoImpl;
import com.cw.lang.common.pagehelper.PageHelper;
import com.cw.lang.mybatis.dto.PageInfo;
import com.cw.lang.mybatis.dto.PageParam;

/**
 * 接口参数字段数据库操作接口实现
 *
 * @author chenw
 * @date 2019-10-31 22:35:52
 */
@Repository
public class FacadeParamFieldDaoImpl extends AbstractBaseDaoImpl<FacadeParamFieldDo, FacadeParamFieldMapper>
    implements FacadeParamFieldDao {
    /**
     * 分页查询
     *
     * @param facadeParamField 条件
     * @param pageParam 分页参数
     * @return
     */
    @Override
    public PageInfo<FacadeParamFieldDo> selectPage(FacadeParamFieldQuery facadeParamField, PageParam pageParam) {
        FacadeParamFieldExample example = buildExample(facadeParamField);
        return PageHelper.<FacadeParamFieldDo>startPage(pageParam.getPageNum(),
            pageParam.getPageSize()).doSelectPageInfo(() -> getMapper().selectByExample(example));
    }

    /**
     * 根据key查询接口参数字段
     *
     * @param id
     * @return
     */
    @Override
    public FacadeParamFieldDo selectByKey(Long id) {
        FacadeParamFieldKeyDo facadeParamFieldKeyDo = new FacadeParamFieldKeyDo();
        facadeParamFieldKeyDo.setId(id);
        return getMapper().selectByPrimaryKey(facadeParamFieldKeyDo);
    }

    /**
     * 根据key删除接口参数字段
     *
     * @param id
     * @return
     */
    @Override
    public int deleteByKey(Long id) {
        FacadeParamFieldKeyDo facadeParamFieldKeyDo = new FacadeParamFieldKeyDo();
        facadeParamFieldKeyDo.setId(id);
        return getMapper().deleteByPrimaryKey(facadeParamFieldKeyDo);
    }

    /**
     * 查询接口参数字段信息
     *
     * @param facadeParamField 条件
     * @return List<FacadeParamFieldDo>
     */
    @Override
    public List<FacadeParamFieldDo> selectByExample(FacadeParamFieldQuery facadeParamField) {
        return getMapper().selectByExample(buildExample(facadeParamField));
    }

    /**
     * 新增接口参数字段信息
     *
     * @param facadeParamField 条件
     * @return int>
     */
    @Override
    public int insertBySelective(FacadeParamFieldDo facadeParamField) {
        if (facadeParamField == null) {
            return -1;
        }
        return getMapper().insertSelective(facadeParamField);
    }

    /**
     * 修改接口参数字段信息
     *
     * @param facadeParamField
     * @return
     */
    @Override
    public int updateBySelective(FacadeParamFieldDo facadeParamField) {
        if (facadeParamField == null) {
            return -1;
        }
        return getMapper().updateByPrimaryKeySelective(facadeParamField);
    }

    /**
     * 构建接口参数字段Example信息
     *
     * @param facadeParamField
     * @return
     */
    public FacadeParamFieldExample buildExample(FacadeParamFieldQuery facadeParamField) {
        FacadeParamFieldExample example = new FacadeParamFieldExample();
        FacadeParamFieldExample.Criteria criteria = example.createCriteria();
        if (facadeParamField != null) {
            //添加查询条件
            if (null != facadeParamField.getId()) {
                criteria.andIdEqualTo(facadeParamField.getId());
            }
            if (com.cw.lang.common.utils.StringUtil.isNotEmpty(facadeParamField.getFieldCode())) {
                criteria.andFieldCodeEqualTo(facadeParamField.getFieldCode());
            }
            if (StringUtil.isNotEmpty(facadeParamField.getRequired())) {
                criteria.andRequiredEqualTo(facadeParamField.getRequired());
            }
            if (null != facadeParamField.getMinLength()) {
                criteria.andMinLengthEqualTo(facadeParamField.getMinLength());
            }
            if (null != facadeParamField.getMaxLength()) {
                criteria.andMaxLengthEqualTo(facadeParamField.getMaxLength());
            }
            if (com.cw.lang.common.utils.StringUtil.isNotEmpty(facadeParamField.getFieldDesc())) {
                criteria.andFieldDescEqualTo(facadeParamField.getFieldDesc());
            }
            if (com.cw.lang.common.utils.StringUtil.isNotEmpty(facadeParamField.getFieldDemo())) {
                criteria.andFieldDemoEqualTo(facadeParamField.getFieldDemo());
            }
            if (null != facadeParamField.getCreateBy()) {
                criteria.andCreateByEqualTo(facadeParamField.getCreateBy());
            }
            if (null != facadeParamField.getCreateDateBegin()) {
                criteria.andCreateDateGreaterThanOrEqualTo(facadeParamField.getCreateDateBegin());
            }
            if (null != facadeParamField.getCreateDateEnd()) {
                criteria.andCreateDateLessThanOrEqualTo(facadeParamField.getCreateDateEnd());
            }
            if (null != facadeParamField.getUpdateBy()) {
                criteria.andUpdateByEqualTo(facadeParamField.getUpdateBy());
            }
            if (null != facadeParamField.getUpdateDateBegin()) {
                criteria.andUpdateDateGreaterThanOrEqualTo(facadeParamField.getUpdateDateBegin());
            }
            if (null != facadeParamField.getUpdateDateEnd()) {
                criteria.andUpdateDateLessThanOrEqualTo(facadeParamField.getUpdateDateEnd());
            }
        }
        return example;
    }
}
